﻿<%@ Page Title="" Language="C#" MasterPageFile="~/administrator/backend.Master" AutoEventWireup="true" CodeBehind="events-add.aspx.cs" Inherits="VQWEB.administrator.events.events_add" %>
<asp:Content ID="Content1" ContentPlaceHolderID="Content_backend" runat="server">
    <form id="frmObjects" action="" method="post">
    </form>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="Script_backend" runat="server">
    <script type="text/javascript">
        ShowToolBar("edit");
        var url_ashx = "/admin/event/handler";
        var url_input = '<%=ResolveUrl("~/administrator/templates/input.tpl") %>';

        $(document).ready(function () {
            if (CheckAtionInPath("add")) {
                loadform(0, "", "", "", "", "", false);
            }
            else if (CheckAtionInPath("edit")) {
                $.get(url_ashx, { view_event: "view_event", Id: GetId() }, function (data) {
                    var obj = $.parseJSON(data);
                    loadform(obj.id, obj.title,obj.timestart,obj.contentstart,obj.timeend,obj.contentend,obj.active);
                });
            }

        });

        function loadform(id, title, timestart, contentstart, timeend, contentend, active) {
            $.jqoteload(url_input, function (tmpl) {

                $("#frmObjects").single("hidden", "event_id", id, null, null, tmpl.input_tpl);
                $("#frmObjects").single("text", "event_title", title, "Tên sự kiện:", null, tmpl.input_tpl);
                $("#frmObjects").single("text", "time_start", timestart, "Thời gian bắt đầu:", null, tmpl.input_tpl);
                $("#frmObjects").single("text", "content_start", contentstart, "Nội dung bắt đầu:", null, tmpl.input_tpl);
                $("#frmObjects").single("text", "time_end", timeend, "Thời gian kết thúc:", null, tmpl.input_tpl);
                $("#frmObjects").single("text", "content_end", contentend, "Nội dung kết thúc", null, tmpl.input_tpl);
                $("#frmObjects").single("checkbox", "event_active", true, "Kich hoat", active, tmpl.input_tpl);
            });

        }


        $(document).on("click", "#btnCancel", function () {
            window.location = "/admin/event/list";
        });
        $(document).on("click", "#btnSave", function () {
            var arr = $("#frmObjects").serializeObject();
            $.post(url_ashx, { add_event: window.escape(arr) }, function (data) {
                alert(data);
                window.location = "/admin/event/list";
            });
        });
    </script>
</asp:Content>
